package com.zeng.nicecommon.util;

import com.zeng.nicecommon.constant.ResponseStatus;
import lombok.Data;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
public class ResponseUtil {

    private Integer status;

    private Date createTime = new Date();

    private Map<String, Object> data = new HashMap<>();

    private String message;

    public ResponseUtil addData(String key,Object value) {
        this.data.put(key, value);
        return this;
    }

    public static ResponseUtil success(String message) {
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.setMessage(message);
        responseUtil.setStatus(ResponseStatus.success.getStatus());
        return responseUtil;
    }
    public static ResponseUtil success(Integer number) {
        ResponseUtil responseUtil = new ResponseUtil();
        String format = String.format("影响记录条数:[%d]条", number);
        responseUtil.setMessage(format);
        responseUtil.setStatus(ResponseStatus.success.getStatus());
        return responseUtil;
    }
    public static ResponseUtil noAuthority(String message) {
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.setMessage(message);
        responseUtil.setStatus(ResponseStatus.noauthority.getStatus());
        return responseUtil;
    }
    public static ResponseUtil badRequest(String message) {
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.setMessage(message);
        responseUtil.setStatus(ResponseStatus.badRequest.getStatus());
        return responseUtil;
    }

    public static ResponseUtil serviceError(String message) {
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.setMessage(message);
        responseUtil.setStatus(ResponseStatus.serviceError.getStatus());
        return responseUtil;
    }

}
